//
//  CAFollowListController.m
//  cascade-realm
//
//  Created by QSC on 3/6/24.
//

#import "CAFollowListController.h"
#import "CAFollowListCell.h"
@interface CAFollowListController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView * tableView;
@end

@implementation CAFollowListController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.navTitle = @"Follow List";
    if (self.type == 2) {
        self.navTitle = @"Block List";
    }
    
    [self.view addSubview:self.tableView];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.view);
            make.top.equalTo(self.navView.mas_bottom);
            make.bottom.equalTo(self.view).offset(-kBottomSafeHeight);
    }];
}

- (UITableView *)tableView{
    if (_tableView == nil) {
        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
        _tableView.dataSource = self;
        [_tableView registerClass:[CAFollowListCell class] forCellReuseIdentifier:@"CAFollowListCell"];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.showsVerticalScrollIndicator = NO;
        
    }
    
    return  _tableView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    CAFollowListCell * cell = [tableView dequeueReusableCellWithIdentifier:@"CAFollowListCell"];
    cell.type = self.type;
    cell.user = self.dataArray[indexPath.row];
    
  
    
    WeakSelf
    cell.removeBlock = ^{
        [weakSelf.dataArray removeObjectAtIndex:indexPath.row];
        [weakSelf.tableView deleteRowAtIndexPath:indexPath withRowAnimation:UITableViewRowAnimationLeft];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [weakSelf.tableView reloadData];
        });
    };

    return  cell;
}


@end
